package com.platform.service.impl;

import com.platform.dao.StandingsDao;
import com.platform.dao.StandingsTypeDao;
import com.platform.entity.StandingsEntity;
import com.platform.entity.StandingsTypeEntity;
import com.platform.service.StandingsService;
import com.platform.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Service实现类
 *
 * @author ocean
 * @email 1141736487@qq.com
 * @date 2019-03-15 16:00:12
 */
@Service("standingsService")
public class StandingsServiceImpl implements StandingsService {
    @Autowired
    private StandingsDao standingsDao;
    @Autowired
    private StandingsTypeDao standingsTypeDao;

    @Override
    public StandingsEntity queryObject(Integer id) {
        return standingsDao.queryObject(id);
    }

    @Override
    public List<StandingsEntity> queryList(Map<String, Object> map) {
        Long userId = ShiroUtils.getUserId();
        if (userId == 1) {
            map.put("createUser", null);
        } else {
            map.put("createUser", userId);
        }
        return standingsDao.queryList(map);
    }

    public StandingsEntity infoByCode(String code) {
        StandingsEntity standings = null;
        Long createUser = ShiroUtils.getUserId();
        StandingsTypeEntity standingsTypeEntity = standingsTypeDao.queryByCodeAndUser(code, createUser);
        if (standingsTypeEntity != null) {
            standings = standingsDao.infoByTypeId(standingsTypeEntity.getId(), createUser);
        }
        if (standings == null) {
            standings = new StandingsEntity();
            standings.setTypeId(standingsTypeEntity.getId());
        }
        return standings;
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return standingsDao.queryTotal(map);
    }

    @Override
    public int save(StandingsEntity standings) {
        standings.setCreateUser(ShiroUtils.getUserId().intValue());
        standings.setCreateTime(new Date());
        return standingsDao.save(standings);
    }

    @Override
    public int update(StandingsEntity standings) {
        return standingsDao.update(standings);
    }

    @Override
    public int delete(Integer id) {
        return standingsDao.delete(id);
    }

    @Override
    public int deleteBatch(Integer[] ids) {
        return standingsDao.deleteBatch(ids);
    }
}
